home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: VC++ v.4.0 conversion problems
- Date: Sat, 20 Jan 1996 00:29:08 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4dpcvt$5gs@news.halcyon.com>
- References: <4dls1n$ldp@eagle.novo.dk>
- NNTP-Posting-Host: blv-pm10-ip8.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- morb@novo.dk (Morten Brun) wrote:
-
- >I am having a lot of problems when compiling under v.4. as I am etting
-
- >a lot of conversions errors due to the new behavior of v.4 like:
- >
- >LPWSTR lpszName;
-
- >GetPrivateProfileStringA("x", "y", "",lpszName, sizeof(lpszName),
- >\\xxx.INI");
-
- >error c26664: cannot convert parm. 4 from unsigned short * to char *
- >or
- >error C2446: '=' : no conversion from 'char *' to 'unsigned char *'
- >error C2664: 'wcstombs' : cannot convert parameter 1 from 'unsigned
- >char [32]' error C2664: 'mbstowcs' : cannot convert parameter 2 from
- >'unsigned char *' to 'const char *'
- >error C2664: 'ctime' : cannot convert parameter 1 from 'unsigned long
- >*' to 'const long *'
- >----------------------------------------------------------------------------------------
- >...
-
- >Regards Morten
-
- The first case involves a UNICODE to ANSI conversion problem.
- The code declares lpszName to point to an array of wide-chars (2-byte
- UNICODE 'characters'), yet the ...A() version of the function
- explicitly invokes the ANSI version of the API (all APIs ending in A
- and taking strings assume ANSI strings). Usually, you just call
- GetPrivateProfileString and macros automatically steer you to the W or
- A incarnations based on whether you've defined UNICODE in the compile.
-
- Lookup things like TCHAR and _TEXT to see more.
-
- The char to unsigned char problems simply say the sign bit will be
- interpreted differently. You can type-cast your way around it if you
- have to.
-
- typedef unsigned char BYTE; // made in some header
- ...
- BYTE myByte = (BYTE) 'c'; // cast to make 'c' appear unsigned
-
- It's best, however, to take your compiler's objections to heart; you
- might introduce bugs by mixing signed and unsigned.
-
- The errors you cited involving const are also really signed/unsigned
- errors. Passing a normal pointer to a function expecting a const
- pointer is perfectly legal; passing a const pointer to a function that
- accepts a normal pointer is an error because the function is saying "I
- could change the pointed to data" and you're saying "don't change what
- this pointer points to."
-
- Does this help?
- --Norm
-
-